package com.javase.algorithm.datastructure.stringsandarrays;

import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

/**
 * 搜索插入位置
 *
 * @author liyanhao
 * @create 2022-06-29 19:03
 * https://leetcode.cn/leetbook/read/array-and-string/cxqdh/
 */
public class SearchInsert {
    public static void main(String[] args) {
        int[] nums = {1, 3, 5, 6};
        int target = 2;
        int i = new SearchInsert().searchInsert(nums, target);
        System.out.println(i);
    }

    public int searchInsert(int[] nums, int target) {
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == target) {
                return i;
            } else if (nums[i] > target) {
                return i ;
            }
        }
        return nums.length;
    }
}
